﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CMS.Data;
using System.Web.Mvc;
using CMS.Service.EnumHelper;
using CMS.Service.Repository;

namespace CMSApplication.Areas.Administration.Models
{
    public class WorkSearchModel
    {
        public string Keys { get; set; }
        public int CustomerId { get; set; }
        public int StaffId { get; set; }
        public DateTime AssignOnFrom { get; set; }
        public DateTime AssignOnTo { get; set; }
        public int Status { get; set; }
        public int OrderBy { get; set; }
        public int Page { get; set; }
        public int Type { get; set; }

        public SelectList SLCustomer { get; set; }
        public SelectList SLStaff { get; set; }
        public SelectList SLStatus { get; set; }
        public SelectList SLOrderBy { get; set; }

        public void GetDataForSL()
        {
            var customer_srv = new CustomerRepository();
            var user_srv = new UserRepositry();

            var customer_lst = new List<KeyValuePair<int, string>>();
            customer_lst.Add(new KeyValuePair<int, string>(0, "- - Tất cả - -"));
            foreach (var item in customer_srv.Search(null, 0, 0, DateTime.MinValue, DateTime.MinValue))
            {
                customer_lst.Add(new KeyValuePair<int, string>(item.Id, string.Format("{0} - {1}", item.Id.ToString().PadLeft(4, '0'), item.Name)));
            }

            var staff_lst = new List<KeyValuePair<int, string>>();
            staff_lst.Add(new KeyValuePair<int, string>(0, "- - Tất cả - -"));
            foreach (var item in user_srv.List().Where(x => x.Status == true))
            {
                staff_lst.Add(new KeyValuePair<int, string>(item.Id, string.Format("{0} - {1}", item.Id.ToString().PadLeft(4, '0'), item.FullName)));
            }

            var status_lst = new List<KeyValuePair<int, string>>();
            status_lst.Add(new KeyValuePair<int, string>(0, "- - Tất cả - -"));
            status_lst.AddRange(EnumHelper.Get_Enum_Wrk_Status());

            var orderby_lst = new List<KeyValuePair<int, string>>() {
                new KeyValuePair<int, string>(0, "- - Mặc định - -"),
                new KeyValuePair<int, string>(1, "Trạng thái"),
                new KeyValuePair<int, string>(2, "Ngày thực hiện"),
                new KeyValuePair<int, string>(3, "Mã nhân viên"),
                new KeyValuePair<int, string>(4, "Mã khách hàng")};

            this.SLCustomer = new SelectList(customer_lst, "Key", "Value");
            this.SLStaff = new SelectList(staff_lst, "Key", "Value");
            this.SLStatus = new SelectList(status_lst, "Key", "Value");
            this.SLOrderBy = new SelectList(orderby_lst, "Key", "Value");
        }

        public WorkSearchModel() { }
    }
}
